<template>
  <div>
    <!-- 提现记录 -->
    <div p-16rpx box-border v-if="routerVal.type === '1'">
      <scroll-view :scroll-top="scrollTop" @scrolltolower="reachBottom"
        :lower-threshold="100" scroll-with-animation :style="{ height: 'calc(100vh + 120rpx)' }"
        :scroll-y="true">
        <div v-if="isShow">
          <div v-if="cashLogData.records.length">
            <div :key="index" v-for="(item, index) in cashLogData.records" mb-20rpx class="order-list" bg-white py-16rpx rounded>

              <div flex justify-between text-28rpx box-border px-30rpx py-10rpx>
                <div>
                  <div>编号：{{item.sn}}</div>
                  <div font-semibold my-16rpx>
                    {{
                      item.distributionCashStatus == "APPLY"? "待处理"
                      : item.distributionCashStatus == "VIA_AUDITING"? "审核通过"
                      : item.distributionCashStatus == "FAIL_AUDITING"? "审核拒绝"
                      : item.distributionCashStatus == "SUCCESS"?"提现成功"
                      : "提现失败"
                    }}
                  </div>
                  <div style="color: #999999;" text-26rpx>{{ item.createTime }}</div>
                </div>
                <template v-if="item.distributionCashStatus == 'VIA_AUDITING'">
                  <div style="color: green;" text-26rpx font-semibold>+{{ unitPrice(item.price, '￥') }}</div>
                </template>
                <template v-else>
                  <div style="color: red;" text-26rpx font-semibold>{{ unitPrice(item.price, '￥') }}</div>
                </template>
              </div>
            </div>
          </div>
          <empty v-if="!cashLogData.records.length" />
        </div>
      </scroll-view>
    </div>
    <!-- 分销业绩 -->
    <div  v-if="routerVal.type === '0'">
      <empty />
    </div>
  </div>
</template>

<script setup lang="ts">
  import {cashLog, distributionOrderList} from "@/api/goods";
  import empty from '@/components/empty/index.vue';
  import { onLoad } from '@dcloudio/uni-app';
  import { unitPrice } from '@/utils/filters';
  const scrollTop = ref<number>(0) //scroll 为0 回到顶部
  const isShow = ref<boolean>(false) //是否展示内容
  const routerVal = ref<any>({})
  const searchForm = ref<any>({
    pageNumber: 1,
    pageSize: 10,
    sort: 'createTime',
    order: 'desc'
  })
  const cashLogData = ref<any>({
    records: [],
    total: 0
  })


  // 触底加载
  function reachBottom() {
    if (searchForm.value.pageSize * searchForm.value.pageNumber < cashLogData.value.total) {
      searchForm.value.pageNumber++
      fetch()
    }
  }

  function init() {
    isShow.value = false
    cashLogData.value.records = []
    searchForm.value.pageSize = 10
    searchForm.value.pageNumber = 1
    fetch()
  }

  async function fetch() {
    // 初始化提现历史
    const res = await cashLog(searchForm.value)
    isShow.value = true
    if (res.data.success) {
      cashLogData.value.records.push(...res.data.result.records)
      cashLogData.value.total = res.data.result.total
    }
  }
  onLoad((options: any) => {
    routerVal.value = options
    //这是修改后的导航栏文字
    uni.setNavigationBarTitle({
      title: options.type === "0" ? '分销业绩' : '提现记录',
    });
  })

  onMounted(() => {
    init()
  })
</script>

<style scoped lang="scss">



</style>
